package com.lc.question.dao;


import com.lc.question.pojo.QuestionNaire;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("questionNaireDao")
public interface IQuestionNaireDao {

    //查看所有问卷表
    @Select("select * from questionnaire")
    public List<QuestionNaire> questionNaireList();

    //根据问卷表ID查询
    @Select("select * from questionnaire where tab_Id=#{tab_Id}")
    public QuestionNaire findQuestionNaireByTabId(int tab_Id);

    //根据发布者ID查询
    @Select("select * from questionnaire where pub_Id=#{pub_Id} order by create_time desc")
    public List<QuestionNaire> findQuestionNaireByPubId(String pub_Id);

    //根据问卷表标题查询
    @Select("select * from questionnaire where tab_title=#{tab_title}")
    public QuestionNaire findQuestionNaireByTitle(String tab_title);

    //根据问卷表标题模糊查询
    @Select("<script>" +
            "select * from questionnaire where tab_title LIKE CONCAT('%',#{arg0},'%') and tab_Id=" +
            "(select tab_Id from userTab where user_Id=#{arg1})" +
            "</script>")
    public QuestionNaire findQueNaireByTitle_user(String tab_title,String user_Id);


    @Update("update questionnaire set tab_title=#{tab_title}," +
            "tab_content=#{tab_content},over_time=#{over_time},t_text=#{t_text}"
            +"where tab_Id=#{tab_Id}")
    public void updateQuestionNaire(QuestionNaire questionNaire);

    @Delete("delete * from questionnaire where tab_Id=#{tab_Id}")
    public void deleteQuestionNaire(int tab_Id);


    @Insert("insert into questionnaire(tab_title,tab_content" +
            ",pub_Id,create_time,over_time,t_text) values(" +
            "#{tab_title},#{tab_content},#{pub_Id},#{create_time},#{over_time},#{t_text})")
    public void addQueNaire(QuestionNaire questionNaire);




}

